let requestUtil = require('@/api/http/request.js');
import {
	tenantId
} from '@/api/http/setting'
import vm from "@/main.js"
//token
export const getTokenAPI = (params) => {
	return requestUtil('/blade-auth/oauth/token', 'post', {
		...params,
		tenantId:tenantId,
		grant_type:"car_customer_applet",
		platform_type:"3",
		scope:"all"
	}, '');
}

//刷新token
let refreshToken = (refresh_token) => {	let header = {		'Tenant-Id': tenantId	};	return requestUtil('blade-auth/oauth/token', 'post', {		tenantId,		refresh_token,		grant_type: "refresh_token",		scope: "all",	}, "", true, header);}

//计算相差时间export const calcDate = (date1, date2) =>{	let date3 = date2 - date1;	let days = Math.floor(date3 / (24 * 3600 * 1000));	let leave1 = date3 % (24 * 3600 * 1000); //计算天数后剩余的毫秒数	let hours = Math.floor(leave1 / (3600 * 1000));	let leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数	let minutes = Math.floor(leave2 / (60 * 1000));	let leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数	let seconds = Math.round(date3 / 1000);	return {		leave1,		leave2,		leave3,		days: days,		hours: hours,		minutes: minutes,		seconds: seconds,	}}

//刷新tokenexport const refreshTokenFun = () => {	// let refreshTime = setInterval(() => {	// 	const date = calcDate(vm.datetime, new Date().getTime());	// 	let tokenTime = parseInt(vm.loginUser.expires_in) - 600;	// 	if (date == 0) return;	// 	if (date.seconds >= tokenTime) {	// 		refreshToken(vm.loginUser.refresh_token).then(	// 			([err,data2]) => {	// 				//重新存储token	// 				if(err) return;	// 				vm.$u.vuex('datetime', new Date().getTime());
	// 				let loginUser = {
	// 					access_token:data2.access_token,
	// 					avatar:data2.avatar,
	// 					expires_in:data2.expires_in,
	// 					nick_name:data2.nick_name,
	// 					phone:data2.phone,
	// 					refresh_token:data2.refresh_token,
	// 					user_id:data2.user_id
	// 				}
	// 				vm.$u.vuex('loginUser', loginUser);	// 			}	// 		);	// 	}	// }, 10000);	// vm.$u.vuex('refreshTime', refreshTime);}


//检查注册情况
export const checkRegisterAPI = (params) => {
	return requestUtil('/iot-device-saas-customer/customer/checkRegister', 'post', {tenantId:tenantId,...params}, '');
}


//获取微信手机号
export const getCustomerWeixinPhoneAPI = (params) => {
	return requestUtil('/iot-device-saas-customer/customer/getCustomerWeixinPhone', 'post', {tenantId:tenantId,...params}, '');
}

//用户注册
export const registerAPI = (params) => {
	return requestUtil('/iot-device-saas-customer/customer/register', 'post', {tenantId:tenantId,platformType:"3",...params}, '');
}

//修改用户昵称
export const editUserAPI = (params) => {
	return requestUtil('/iot-device-saas-customer/customer/update', 'post', params, '');
}

//发送短信验证码
export const sendNoteAPI = (params) => {
	return requestUtil('/blade-resource/sms/endpoint/send-validate', 'post', params, '');
}


//验证短信验证码的正确性
export const validateNoteAPI = (params) => {
	return requestUtil('/blade-resource/sms/endpoint/validate-message', 'post', params, '');
}